package thread.thread_04_27.use_timer;

import java.util.Timer;
import java.util.TimerTask;

public class UseTimer {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();      // 闹钟
        TimerTask task = new TimerTask() {  // 闹钟到时间后要做的任务
            @Override
            public void run() {
                System.out.println("闹钟响了");
            }
        };

        timer.schedule(task, 5000); // t1
        timer.schedule(task, 4000); // t2
        timer.schedule(task, 3000); // t3
        timer.schedule(task, 2000); // t4
        timer.schedule(task, 1000); // t5

        timer.schedule(task, 1500); // t6
        // 1s t5 1s t4 1s t3 0.5s t6 0.5s t2 1s t1
//        timer.scheduleAtFixedRate(task, 1000, 2000);
        while (true) {} // 主线程死循环，所以之后的打印，一定不是主线程打印的
    }
}
